/*
 * @lc app=leetcode.cn id=7 lang=javascript
 *
 * [7] 整数反转
 */

// @lc code=start
/**
 * @param {number} x
 * @return {number}
 */
var reverse = function (x) {
    let negative = false
    if (x < 0) {
        negative = true
        x = -x
    }
    let ans = 0
    while (x > 0) {
        ans = ans * 10 + x % 10
        x = parseInt(x / 10)
    }
    if (negative) ans = -ans
    let max = Math.pow(2, 31) - 1
    let min = -Math.pow(2, 31)
    if (ans >= max || ans <= min) {
        return 0
    }
    return ans
};
// @lc code=end
// @after-stub-for-debug-begin
module.exports = reverse;
// @after-stub-for-debug-end